import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

List<Integer> readIntFile(String filePath) {
    List<Integer> lines = new ArrayList<>();
    try (BufferedReader br = new BufferedReader(new FileReader(filePath))) {
        String line;
        while ((line = br.readLine())!= null) {
            try {
                int num = Integer.parseInt(line.trim());
                lines.add(num);
            } catch (NumberFormatException ignored) {
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return lines;
}

{
    long startTime = System.currentTimeMillis();
    List<Integer> dataList = readIntFile("C:\\Users\\ASUS\\Desktop\\coursework2_files\\sort10.txt");
    Integer[] dataArray = dataList.toArray(new Integer[0]);
    if (dataArray.length > 0) {
        long sortStartTime = System.currentTimeMillis();
        java.util.Arrays.sort(dataArray);
        long sortEndTime = System.currentTimeMillis();
        System.out.println("排序所用时间（毫秒）: " + (sortEndTime - sortStartTime));
    } else {
        System.out.println("排序所用时间（毫秒）: 0");
    }
    long endTime = System.currentTimeMillis();
}

